<?php
/**
 * Interface to add/remove classrooms from the system
 */
?>
<html>
<head>
<?php
require_once '../dbms_university_courses_mvc/Model/model_require_once.php';
?>
</head>
<body>
<h2>University Departments</h2>
<?php
$departments = Department::getDepartments ();
/* @var $instructorDepartment InstructorDepartment */
$instructorDepartments = InstructorDepartment::getInstructorDepartments();
/* @var $department Department */
/* @var $instructorDepartment InstructorDepartment */
Department::instantiate_javascript_objects($departments);
InstructorDepartment::instantiate_javascript_objects($instructorDepartments);
?>

<table>
	<tr>
		<th>Name</th>
		<th>Delete</th>
		<th>Instructors</th>
	</tr>
<?php
foreach ( $departments as $department ) {
	?>
	<tr>
		<td><?php
	echo $department->print_department_name_input_setter ();
	?></td>
		<td>
		<?php $department->print_delete_button(true, "refreshPage");?>
		</td>
		<td>
		<table>
	
	<?php
	$instructorDepartments = $department->getInstructorDepartments();
	foreach ( $instructorDepartments as $instructorDepartment ) {
		/* @var $instructor Instructor */
		$instructor = Instructor::constructFrom_instructor_id ( $instructorDepartment->get_instructor_id () );
		?>
	<tr>
				<td colpsan="2"><?php
		/* @var $profile Profile */
		$profile = Profile::constructFrom_profile_id ( $instructor->get_profile_id () );
		echo $profile->get_first_name () . " " . $profile->get_last_name ();
		?></td>
				<td>
				<?php $instructorDepartment->print_delete_button(true, "refreshPage");?>
				</td>
			</tr>
	<?php
	}
	?>
	</table>
		</td>
	</tr>
	<?php
}

//insert new course via ajax call
?>
</table>
<br>
<br>
<h2>Add New Department</h2>
<?php
Department::print_Department_add ( "refreshPage" );
?>
<br>
<br>
<h2>Add Instructor to Department</h2>
<script type="text/javascript">
var instructorId;
function setInstructorId(id){
	instructorId = id;
}

var departmentId;
function setDepartmentId(id){
	departmentId = id;
}
</script>
<select onchange="setInstructorId(this.value)">
	<option>Select Instructor</option>
<?php
$instructors = Instructor::getInstructors ();
foreach ( $instructors as $instructor ) {
	$profile = Profile::constructFrom_profile_id ( $instructor->get_profile_id () );
	?>
<option value="<?php
	echo $instructor->get_instructor_id ();
	?>"><?php
	echo $profile->get_first_name () . " " . $profile->get_last_name ();
	?></option>
<?php
}
?>
</select>
<?php
Department::print_Department_autocomplete(Department::getDepartments(), "department_name", "", "setDepartmentId");
?><input class="ui-corner-all ui-state-default" type="button"
	onclick="insertNewInstructorDepartment(instructorId, departmentId, refreshPage)"
	value="Add Instructor to Department"
/>
</body>
</html>